package com.LeeCode;

import java.util.HashSet;

/**
 * 从链表中移除在数组中存在的节点
 */

public class Code3217 {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3};
        int[] arr = {1, 2, 3, 4, 5};
        ListNode head = Utils.arrayToListNode(arr);
        Utils.printListNode(new Code3217().modifiedList(nums, head));
    }

    public ListNode modifiedList(int[] nums, ListNode head) {
        ListNode dummyHead = new ListNode(0, head);
        ListNode cur = dummyHead;
        HashSet<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }

        while (cur.next != null) {
            if (set.contains(cur.next.val)) {
                cur.next = cur.next.next;
            } else {
                cur = cur.next;
            }
        }
        return dummyHead.next;
    }
}
